package com.et114.components.mail;

import java.util.Map;

import org.springframework.mail.SimpleMailMessage;

/**
 * @author guanhw
 * SIMPALE
 */
public class MockMailService extends MailService {

	public void send( SimpleMailMessage msg ) {
		StringBuffer mail = new StringBuffer();
		mail.append( getMailHeader( msg ) + "\n" );
		mail.append( msg.getText() );
		logger.info( mail.toString() );
	}


	public void send( SimpleMailMessage msg , String templateName , Map model ) throws Exception {
		StringBuffer mail = new StringBuffer();
		mail.append( getMailHeader( msg ) + "\n" );
		mail.append( generateEmailContent( templateName , model ) );
		logger.info( mail.toString() );
	}

	protected String getMailHeader( SimpleMailMessage msg ) {
		StringBuffer header = new StringBuffer();

		header.append("To: ");
		
		String[] tos = msg.getTo() ; 
		for ( int i = 0 ; i < tos.length ; i ++  ) {
			header.append( tos[ i ] ).append( ";" );
		}
		header.append( "\nFrom: " + msg.getFrom() );
		header.append( "\nSubject: " + msg.getSubject() );
		return header.toString();
	}
}
